package com.ricky04;

public class THreadDemo {
    public static void main(String[] args) throws InterruptedException {
        ReaderThread readerThread = new ReaderThread();
        readerThread .start();
        Thread.sleep(500);//主线程阻塞
//        ready=true;//改值
        readerThread.stopThread();
        Thread.sleep(1000);
        System.out.println("主线程结束");
    }
}

/**
 * 子线程无法终止
 */
class ReaderThread extends Thread{
//    private volatile   boolean ready;
    private static   boolean ready;
    @Override
    public void run() {
        while (!ready){
                int i=0;
//            System.out.print(".");  //如果是此种方式的话 会同步锁  会刷新工作内存   但是不加这个 有的机器上又是可以线程正常终止的  不会死循环
        }
        System.out.println();
        System.out.println("子结束");
    }
    public void stopThread(){
        System.out.println("更改了");
        this.ready=true;
    }
}
